﻿using System;
using System.Data;
using System.Configuration;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using System.Security.Policy;
using System.IO;
using System.Text.RegularExpressions;

namespace net.veekee.common.data.csv
{
    public class CSVDynamicClass : DynamicClass
    {
        public CSVDynamicClass(String name)
            : base(name)
        {
            Log.GetInstance().Debug("Creating new CSV dynamic class: {0}", name);
            this.Inherited = "net.veekee.common.CSVEntry";
        }

        public void AddGetSet(int idx, String FieldName, String Type = "String")
        {
            FieldName = new Regex(@"\W").Replace(FieldName, "_");
            Log.GetInstance().Debug("{0}: Adding field {1} (index={2})", this.ClassName, FieldName, idx);

            String addOn = @"
        private {0} internal{1} = default({0});
        [CSVBean(Index = {2})]
        public {0} {1} {{
            get
            {{
                return internal{1};
            }}
            set
            {{
                internal{1} = value;
            }}
        }}
";
            this.sourceCodeAddLine(this.sourceAddOn, String.Format(addOn, Type, FieldName, idx));
        }
    }
}
